<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.ViewCompraTitle}"></h:outputText>
        </ui:define>

        <ui:define name="menuLateral">

            <h:form id="formLateralMenuCompraView">
                <h:panelGroup>
                    <p:slideMenu style="width: 120px">
                        <p:menuitem value="#{bundle.ListCompraTitle}" 
                                    action="#{compraController.prepareList}" ajax="false"
                                    icon="ui-icon-arrowreturnthick-1-w" />
                        <p:separator />
                        <p:submenu label="Cadastros Obrigatórios" icon="ui-icon-suitcase">
                            <p:submenu label="Pagamentos">
                                <p:menuitem id="menuLateralCondicaoPagamento" 
                                            value="#{bundle.CreateCondicaoPagamentoShowAllLink}"
                                            action="/paginasEntidades/condicaoPagamento/List" ajax="false"/>
                                <p:menuitem id="menuLateralFormaPagamento" 
                                            value="#{bundle.CreateFormaPagamentoShowAllLink}"
                                            action="/paginasEntidades/formaPagamento/List" ajax="false"/>
                            </p:submenu>
                            <p:submenu label="Participantes">
                                <p:menuitem id="menuLateralFornecedor" 
                                            value="#{bundle.CreateFornecedorShowAllLink}"
                                            action="/paginasEntidades/fornecedor/List" ajax="false"/>
                            </p:submenu>
                            <p:submenu label="Produtos">
                                <p:menuitem id="menuLateralProduto" 
                                            value="#{bundle.CreateProdutoShowAllLink}"
                                            action="/paginasEntidades/produto/List" ajax="false"/>
                                <p:menuitem id="menuLateralUnidadeMedida" 
                                            value="#{bundle.CreateUnidadeMedidaShowAllLink}"
                                            action="/paginasEntidades/unidadeMedida/List" ajax="false"/>
                                <p:menuitem id="menuLateralTipoProduto" 
                                            value="#{bundle.CreateTipoProdutoShowAllLink}"
                                            action="/paginasEntidades/tipoProduto/List" ajax="false"/>
                            </p:submenu>
                        </p:submenu>
                    </p:slideMenu>
                </h:panelGroup>
            </h:form>

        </ui:define>

        <ui:define name="body">
            <h:panelGroup id="messagePanel" layout="block">
                <p:growl />
            </h:panelGroup>

            <h:form id="formCompraView">
                <p:panelGrid id="pgCompraView" columns="7">
                    <h:outputLabel value="#{bundle.ViewCompraLabel_dataCompra}" for="dataCompra" />
                    <p:inputText id="dataCompra" value="#{compraController.selected.dataCompra}" 
                                 title="#{bundle.ViewCompraTitle_dataCompra}" disabled="true" >
                        <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                    </p:inputText>

                    <h:outputLabel value="#{bundle.ViewCompraLabel_fornecedor}" for="fornecedor" />
                    <p:selectOneMenu id="fornecedor" value="#{compraController.selected.fornecedor}" 
                                     label="#{bundle.ViewCompraTitle_fornecedor}" required="true" 
                                     disabled="true" 
                                     requiredMessage="#{bundle.ViewCompraRequiredMessage_fornecedor}">
                        <f:selectItems value="#{fornecedorController.itemsAvailableSelectOne}"/>
                    </p:selectOneMenu>
                    
                </p:panelGrid>

                <br/>
                <br/>
            </h:form>

            <h:form id="formCompraItensCompraList">

                <h:panelGroup>

                    <p:dataTable id="tableCompraItensCompra" value="#{compraController.itemsItensCompra}" var="item">

                        <f:facet name="header">#{bundle.ListItensCompraTitle}</f:facet>

                        <p:column>
                            <f:facet name="header">#{bundle.ListItensCompraTitle_itensCompraPK_item}</f:facet>
                            <h:outputText value="#{compraController.itemsItensCompra.rowIndex+1}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">#{bundle.ListItensCompraTitle_produto}</f:facet>
                            <h:outputText value="#{item.produto.toString()}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">#{bundle.ListItensCompraTitle_quantidade}</f:facet>
                            <h:outputText value="#{item.quantidade}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">#{bundle.ListProdutoTitle_valor}</f:facet>
                            <h:outputText value="R$ #{item.valor}" />
                            <f:facet name="footer">
                                <h:outputText value="Valor Total da Compra " />
                            </f:facet>
                        </p:column>

                        <p:column>
                            <f:facet name="header">Valor Total</f:facet>
                            <h:outputText value="R$ #{item.valorTotal}" />
                            <f:facet name="footer">
                                <h:outputText value="R$ #{compraController.valorTotalCompra}" />
                            </f:facet>
                        </p:column>

                    </p:dataTable>
                </h:panelGroup>

                <br/>
                <br/>

            </h:form>

            <h:form id="formCompraCondicoesCompraList">

                <h:panelGroup>
                    <p:dataTable id="tableCompraCondicoesCompra" value="#{compraController.itemsCondicoesCompra}" 
                                 var="item" style="border:solid 1px" >

                        <f:facet name="header">#{bundle.ListCompraTitle}</f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCondicoesCompraTitle_condicaoPagamento}"/>
                            </f:facet>
                            <h:outputText value="#{item.condicaoPagamento.toString()}"/>
                            <f:facet name="footer">
                                <h:outputText value="Saldo a Pagar " />
                            </f:facet>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCondicoesCompraTitle_condicaoPagamento}"/>
                            </f:facet>
                            <h:outputText value="#{item.valor}"/>
                            <f:facet name="footer">
                                <h:outputText 
                                    value="R$ #{(compraController.valorTotalCompra - compraController.valorTotalCondicoesCompra)}" />
                            </f:facet>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCondicoesCompraTitle_observacao}"/>
                            </f:facet>
                            <h:outputText value="#{item.observacao}"/>
                            <f:facet name="footer">
                                <h:outputText value="Soma dos Pagamentos " />
                            </f:facet>
                        </p:column>

                    </p:dataTable>
                </h:panelGroup>

            </h:form>

        </ui:define>
    </ui:composition>

</html>
